<?php
//获取提交数据
$username = $_POST['username'];//获取提交用户名
$password = $_POST['password'];//获取提交密码
$void = $_POST['void'];
//连接数据库
$db_host = "127.0.0.1";//填写自己的数据库地址
$db_user = "root";//填写自己的数据库用户名
$db_pwd = "root";//填写自己的数据库密码
$db_name = "Users";//填写自己的数据库库名
$db_port = 3306;//数据库端口号，默认3306

$con = mysqli_connect($db_host, $db_user, $db_pwd, $db_name, $db_port);//连接数据库，且定位到指定数据库
if (!$con) {
    die("error:" . mysqli_connect_error());//返回最近调用函数的最后一个错误描述。
}
//用来检验是否正确传参
//var_dump($username);
//var_dump($password);
//var_dump($void);
if ($void === null) {
//    学生端登录
    $sql = "select void,username,password from User where void=1 AND username='$username' AND password='$password';";
    $result = mysqli_query($con, $sql);
    $row = mysqli_num_rows($result);
    if (!$row) {
        echo "<h1>用户名,密码错了!或者您是个老师,请勾选老师登录!</h1>";
    } else {
//        echo "<script>location='student.html'</script>";
        header("Location: ../view/student.html");
    }
} else {
// 老师端登录
    $sql = "select void,username,password from User where void='$void' AND username='$username' AND password='$password';";
    $result = mysqli_query($con, $sql);
    $row = mysqli_num_rows($result);
    if (!$row) {
        echo "<h1>小同学,不要调气哦!你只是个学生!请取消教师登录!</h1>";
    } else {
        header("Location: ../view/teacher.html");
    }
}

